home *** CD-ROM | disk | FTP | other *** search
/ Multicollection 5 Soft 1997 / Multicollection 5 soft 1997 (Win NT 4.0 Work, Serv, OS2).iso / utils.w95 / r-win95 / disk2 / rwinsdk / sample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-15  |  8.9 KB  |  299 lines

  1. /***********************************************************************
  2.  *
  3.  *             sample.c
  4.  *
  5.  *  The example of using RWUSER.DLL library.       Proxima Systems 
  6.  ***********************************************************************/
  7.  
  8. #include "SAMPLE.h"
  9. #include "rwuser.h"
  10.  
  11.  
  12. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  13. {
  14.  MSG        msg;
  15.  int        nRc;
  16.  
  17.  strcpy(szAppName, "SAMPLE");
  18.  hInst = hInstance;
  19.  if(!IsRWINDrv(hInst)) return FALSE;
  20.  if(!hPrevInstance)
  21.    {
  22.     if ((nRc = nCwRegisterClasses()) == -1)
  23.       {
  24.        LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString));
  25.        MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  26.        return nRc;
  27.       }
  28.    }
  29.  
  30.  hWndMain = CreateWindow(
  31.                 szAppName,
  32.                 "Sample",
  33.                 WS_CAPTION      |
  34.                 WS_SYSMENU      |
  35.                 WS_MINIMIZEBOX  |
  36.                 WS_MAXIMIZEBOX  |
  37.                 WS_THICKFRAME   |
  38.                 WS_CLIPCHILDREN |
  39.                 WS_OVERLAPPED,
  40.                 CW_USEDEFAULT, 0,
  41.                 CW_USEDEFAULT, 0,
  42.                 NULL,
  43.                 NULL,
  44.                 hInst,
  45.                 NULL);
  46.  
  47.  
  48.  if(hWndMain == NULL)
  49.    {
  50.     LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
  51.     MessageBox(NULL, szString, NULL, MB_ICONEXCLAMATION);
  52.     return IDS_ERR_CREATE_WINDOW;
  53.    }
  54.  
  55.  ShowWindow(hWndMain, nCmdShow);
  56.  
  57.  while(GetMessage(&msg, NULL, 0, 0))
  58.    {
  59.     TranslateMessage(&msg);
  60.     DispatchMessage(&msg);
  61.    }
  62.  
  63.  
  64.  CwUnRegisterClasses();
  65.  return msg.wParam;
  66. }
  67.  
  68.  
  69. BOOL IsRWINDrv (HANDLE hInstance)
  70. {
  71. char szBuffer [128] ;
  72.  
  73. GetPrivateProfileString ("boot", "keyboard.drv", " ", szBuffer, sizeof(szBuffer), "system.ini") ;
  74. if (lstrcmpi ((LPSTR)szBuffer, "kbdrwin.drv") != 0)
  75.     {
  76.     MessageBox (GetFocus(), "This program requires R-WIN keyboard driver.", szAppName, MB_ICONSTOP | MB_OK) ;
  77.     return FALSE ;
  78.     }
  79. return TRUE ;
  80. }
  81.  
  82.  
  83. LONG FAR PASCAL WndProc(HWND hWnd, WORD Message, WORD wParam, LONG lParam)
  84. {
  85.  HMENU      hMenu=0;
  86.  HBITMAP    hBitmap=0;
  87.  HDC        hDC;
  88.  PAINTSTRUCT ps;
  89.  int        nRc=0;
  90.  
  91.  WORD    wCurMode ;
  92.  BYTE    bCurHotkey ;
  93.  BYTE    bMaxHotkeys ;
  94.  char   szHotkey[32] ;
  95.  char   szLayoutName[64] ;
  96.  WORD   wRetValue ;
  97.  BOOL   bPriDllLoaded ;
  98.  BOOL   bSecDllLoaded ;
  99.  
  100.  static char CurModeString[128] ;
  101.  static char CurHotkeyString[128] ;
  102.  static char PriLibraryString[128] ;
  103.  static char SecLibraryString[128] ;
  104.  
  105.  
  106.  
  107.  switch (Message)
  108.    {
  109.     case WM_COMMAND:
  110.          switch (wParam)
  111.            {
  112.             case IDM_F_GETKBDMODE:
  113.                  wCurMode = GetKbdMode() ;
  114.                  wsprintf(CurModeString, "Current keyboard mode = %i", wCurMode);
  115.                  InvalidateRect(hWnd, NULL, TRUE) ;
  116.                  break;
  117.  
  118.             case IDM_F_SETKBDMODE:
  119.                  MessageBox(hWnd, "Press OK to change keyboard mode...", "Sample", MB_OK) ;
  120.                  wCurMode = GetKbdMode() ;
  121.                  if (wCurMode == 1) SetKbdMode(2) ;
  122.                      else if (wCurMode == 2) SetKbdMode(1) ;
  123.  
  124.                  /* Fill the string CurModeString[] */
  125.                  SendMessage(hWnd, WM_COMMAND, IDM_F_GETKBDMODE, 0L);
  126.                  InvalidateRect(hWnd, NULL, TRUE) ;
  127.                  break;
  128.  
  129.             case IDM_F_GETKBDHOTKEY:
  130.                  bCurHotkey = LOBYTE(GetKbdHotkey()) ;
  131.                  switch (bCurHotkey)
  132.                  {
  133.                  case HK_RCTRL:
  134.                      lstrcpy( szHotkey, "Right Ctrl") ;
  135.                      break ;
  136.  
  137.                  case HK_LSHIFT:
  138.                      lstrcpy( szHotkey, "Left Shift") ;
  139.                      break ;
  140.  
  141.                  case HK_RSHIFT:
  142.                      lstrcpy( szHotkey, "Right Shift") ;
  143.                      break ;
  144.  
  145.                  case HK_SHIFTSHIFT:
  146.                      lstrcpy( szHotkey, "Right Shift + Left Shift") ;
  147.                      break ;
  148.  
  149.                  case HK_CTRLSHIFT:
  150.                      lstrcpy( szHotkey, "LeftShift+LeftCtrl / RightShift+RightCtrl") ;
  151.                      break ;
  152.  
  153.                  case HK_ALTSHIFT:
  154.                      lstrcpy( szHotkey, "LeftShift+LeftAlt / RightShift+RightAlt") ;
  155.                      break ;
  156.  
  157.                  case HK_LCTRL:
  158.                  default:
  159.                      lstrcpy( szHotkey, "Left Ctrl") ;
  160.                      break ;
  161.                  }
  162.                  lstrcpy(CurHotkeyString, "Current hotkey = ");
  163.                  lstrcat(CurHotkeyString, szHotkey) ;
  164.                  InvalidateRect(hWnd, NULL, TRUE) ;
  165.                  break;
  166.  
  167.             case IDM_F_SETKBDHOTKEY:
  168.                  bCurHotkey = LOBYTE(GetKbdHotkey()) ;
  169.                  MessageBox(hWnd, "Press OK to scroll hotkey...", "Sample", MB_OK) ;
  170.                  bCurHotkey++;
  171.                  bMaxHotkeys = HIBYTE(GetKbdHotkey());
  172.                  if (bCurHotkey > bMaxHotkeys) bCurHotkey = 1 ;  // = HK_LCTRL
  173.                  SetKbdHotkey((WORD)bCurHotkey) ;
  174.                  /* Fill the string CurHotkeyString[]  */
  175.                  SendMessage(hWnd, WM_COMMAND, IDM_F_GETKBDHOTKEY, 0L);
  176.                  InvalidateRect(hWnd, NULL, TRUE) ;
  177.                  break;
  178.  
  179.             case IDM_F_GETKBDDLLSSTATUS:
  180.                  wRetValue = GetKbdDllsStatus() ;
  181.                  if ( (wRetValue & 0x0001) > 0 )
  182.                          {
  183.                           bPriDllLoaded = TRUE ;
  184.  
  185.                           lstrcpy (PriLibraryString, "1-st DLL status: Loaded") ;
  186.                          GetPrivateProfileString("boot.description", "keyboard.dll",
  187.                               "", szLayoutName, 64, "system.ini" ) ;
  188.                          lstrcat(PriLibraryString,"    (layout in 1-st mode: ") ;
  189.                          lstrcat(PriLibraryString,szLayoutName) ;
  190.                          lstrcat(PriLibraryString, ")") ;
  191.                           }
  192.                          else
  193.                          {
  194.                           bPriDllLoaded = FALSE ;
  195.                           lstrcpy (PriLibraryString, "1-st DLL status: Not loaded    (default layout: US)") ;
  196.                           }
  197.  
  198.                  if ( (wRetValue & 0x0002) > 0 )
  199.                          {
  200.                           bSecDllLoaded = TRUE ;
  201.                           lstrcpy (SecLibraryString, "2-nd DLL status: Loaded") ;
  202.                          GetPrivateProfileString("boot.description", "secondkeyb.dll",
  203.                               "", szLayoutName, 64, "system.ini" ) ;
  204.                          lstrcat(SecLibraryString,"    (layout in 2-nd mode: ") ;
  205.                          lstrcat(SecLibraryString,szLayoutName) ;
  206.                          lstrcat(SecLibraryString, ")") ;
  207.                           }
  208.                          else
  209.                          {
  210.                           bSecDllLoaded = FALSE ;
  211.                           lstrcpy (SecLibraryString, "2-nd DLL status: Not loaded    (default layout: US)") ;
  212.                           }
  213.                  InvalidateRect(hWnd, NULL, TRUE) ;
  214.                  break;
  215.  
  216.             case IDM_F_ABOUT:
  217.                  MessageBox(hWnd, "Sample application calls the functions exported by RWUSER.DLL library to show the features of R-WIN keyboard driver.\r\r Copyright (c) 1991-95 Proxima Systems. All rights reserved.",
  218.                      "About Sample", MB_OK) ;
  219.                  break;
  220.  
  221.             default:
  222.                 return DefWindowProc(hWnd, Message, wParam, lParam);
  223.            }
  224.          break;
  225.  
  226.     case WM_KEYUP:
  227.              if ((wParam == VK_PRI_MODE) || ( wParam == VK_SEC_MODE))
  228.              {
  229.                  if (wParam == VK_PRI_MODE) wCurMode = 1 ;
  230.                                  else wCurMode = 2 ;
  231.                     MessageBeep(0) ;
  232.                  wsprintf(CurModeString, "Current mode = %i (received WM_KEYUP)", wCurMode);
  233.                  InvalidateRect(hWnd, NULL, TRUE) ;
  234.              }
  235.          break;
  236.  
  237.  
  238.     case WM_PAINT:
  239.          memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  240.          hDC = BeginPaint(hWnd, &ps);
  241.          SetBkMode(hDC, TRANSPARENT);
  242.  
  243.          TextOut(hDC, 10, 10, CurModeString, lstrlen(CurModeString));
  244.          TextOut(hDC, 10, 30, CurHotkeyString, lstrlen(CurHotkeyString));
  245.  
  246.          TextOut(hDC, 10, 45, PriLibraryString, lstrlen(PriLibraryString));
  247.          TextOut(hDC, 10, 60, SecLibraryString, lstrlen(SecLibraryString));
  248.  
  249.          EndPaint(hWnd, &ps);
  250.          break;
  251.  
  252.     case WM_CLOSE:
  253.          DestroyWindow(hWnd);
  254.          if (hWnd == hWndMain)
  255.            PostQuitMessage(0);
  256.         break;
  257.  
  258.     default:
  259.          return DefWindowProc(hWnd, Message, wParam, lParam);
  260.    }
  261.  return 0L;
  262. }
  263.  
  264.  
  265. int nCwRegisterClasses(void)
  266. {
  267.  WNDCLASS   wndclass;
  268.  memset(&wndclass, 0x00, sizeof(WNDCLASS));
  269.  
  270.  
  271.  wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
  272.  wndclass.lpfnWndProc = WndProc;
  273.  wndclass.cbClsExtra = 0;
  274.  wndclass.cbWndExtra = 0;
  275.  wndclass.hInstance = hInst;
  276.  wndclass.hIcon = LoadIcon(hInst, "SAMPLE");
  277.  wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  278.  wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  279.  wndclass.lpszMenuName = szAppName;
  280.  wndclass.lpszClassName = szAppName;
  281.  if(!RegisterClass(&wndclass))
  282.    return -1;
  283.  
  284.  
  285.  return(0);
  286. }
  287.  
  288.  
  289. void CwUnRegisterClasses(void)
  290. {
  291.  WNDCLASS   wndclass;
  292.  memset(&wndclass, 0x00, sizeof(WNDCLASS));
  293.  
  294.  UnregisterClass(szAppName, hInst);
  295. }
  296.  
  297.  
  298.  
  299.